package com.jiezuo.flowable.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;


import com.jiezuo.common.base.BaseController;
import com.jiezuo.common.enums.ResultEnums;
import com.jiezuo.common.util.PageUtil;
import com.jiezuo.common.util.ResultUtil;
import com.jiezuo.common.vo.PageVo;
import com.jiezuo.common.vo.Result;
import com.jiezuo.flowable.entity.MyFormInformation;
import com.jiezuo.flowable.service.MyFormInformationService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
* @description   动态表单信息记录表
* @author        庞留杰
* @date          2024/03/27 10:03
* @version       V1.0
**/
@Slf4j
@Transactional
@RequestMapping("/myFormInformation")
@RestController
//动态表单信息记录表", tags = {"动态表单信息记录表接口"})
public class MyFormInformationController  extends BaseController{

    @Autowired
    private MyFormInformationService service;

    //查询带分页列表", notes = "查询带分页列表")
    @GetMapping("/findPage")
    public Result<IPage<MyFormInformation>> findPage(@ModelAttribute PageVo pageVo,@ModelAttribute MyFormInformation myFormInformation) {
        IPage<MyFormInformation> page = service.findPage(PageUtil.initMpPage(pageVo),myFormInformation);
        return new ResultUtil<IPage<MyFormInformation>>().setData(page);
    }

    //查询不带分页列表", notes = "查询不带分页列表")
    @GetMapping("/findList")
    public Result<List<MyFormInformation>> findList(@ModelAttribute MyFormInformation myFormInformation) {
        List<MyFormInformation> list = service.findList(myFormInformation);
        return new ResultUtil<List<MyFormInformation>>().setData(list);
    }

    //通过ID查询", notes = "通过ID查询")
    @GetMapping("/findById")
    public Result<MyFormInformation> findById(String id) {
        MyFormInformation myFormInformation = service.findById(id);
        return new ResultUtil<MyFormInformation>().setData(myFormInformation);
    }

    //添加", notes = "添加")
    @PostMapping("/save")
    public Result save(@RequestBody MyFormInformation myFormInformation) {
        boolean boo = service.add(myFormInformation);
        if(boo){
            return new ResultUtil().setSuccessMsg(ResultEnums.OK.getReasonPhraseCN());
        }else {
            return new ResultUtil().setErrorMsg(ResultEnums.FAIL.getReasonPhraseCN());
        }
    }

    //修改", notes = "修改")
    @PostMapping("/update")
    public Result update(@RequestBody MyFormInformation myFormInformation) {
        boolean boo = service.update(myFormInformation);
        if(boo){
            return new ResultUtil().setSuccessMsg(ResultEnums.OK.getReasonPhraseCN());
        }else {
            return new ResultUtil().setErrorMsg(ResultEnums.FAIL.getReasonPhraseCN());
        }
    }

    @PostMapping("/addOrUpdate")
    public Result addOrUpdate(@RequestBody MyFormInformation myFormInformation) {
        boolean boo = service.saveOrUpdate(myFormInformation);
        return new ResultUtil().setData(myFormInformation);
    }

    //删除", notes = "删除【逻辑删除】")
    @PostMapping("/delete/{id}")
    public Result delete(@PathVariable String id) {
        boolean boo = service.delete(id);
        if(boo){
            return new ResultUtil().setSuccessMsg(ResultEnums.OK.getReasonPhraseCN());
        }else {
            return new ResultUtil().setErrorMsg(ResultEnums.FAIL.getReasonPhraseCN());
        }
    }


    @PostMapping("/updateFormBusinessIdById")
    public Result updateFormBusinessIdById(@RequestBody Map<String,Object> params) {
        boolean boo = service.updateFormBusinessIdById(params);
        return new ResultUtil().setSuccessMsg(ResultEnums.OK.getReasonPhraseCN());
    }


}
